package com.seeyou.lake.ui

import android.app.Activity
import android.content.Intent
import androidx.core.view.ViewCompat
import com.seeyou.lake.base.MyBaseActivity
import com.seeyou.lake.base.EventBusVo
import com.seeyou.lake.bean.ArticleBean
import com.seeyou.lake.databinding.ActivityArticleDetailBinding
import com.seeyou.lake.util.GlideUtil
import com.seeyou.lake.viewmodel.ModifyViewModel
import com.seeyou.lake.widget.DeleteConfirmDialog
import com.zackratos.ultimatebarx.ultimatebarx.navigationBar
import com.zackratos.ultimatebarx.ultimatebarx.statusBar
import org.greenrobot.eventbus.EventBus

class ArticleDetailActivityMy : MyBaseActivity<ActivityArticleDetailBinding, ModifyViewModel>() {

    companion object {
        fun open(activity: Activity, articleBean: ArticleBean) {
            val intent = Intent(activity, ArticleDetailActivityMy::class.java)
            intent.putExtra("articleBean", articleBean)
            activity.startActivity(intent)
        }
    }

    override fun myViewModel(): ModifyViewModel {
        return ModifyViewModel()
    }

    override fun yourViewBing(): ActivityArticleDetailBinding {
        return ActivityArticleDetailBinding.inflate(layoutInflater)
    }

    override fun init() {
        statusBar {
            transparent()
        }

        navigationBar {
            transparent()
        }

       val articleBean = intent.getSerializableExtra("articleBean") as ArticleBean
        GlideUtil.loadRoundImage(this,articleBean.url,10,mViewBinding.ivArticle)
        mViewBinding.tvArticleTitle.text = articleBean.title
        mViewBinding.tvArticleContent.text = articleBean.content
        ViewCompat.setTransitionName(mViewBinding.ivArticle, "shareImage")

        val deleteConfirmDialog =  DeleteConfirmDialog(this).setPositiveButton {
            mVModel.deleteArticle(articleBean.pid)
        }
        mViewBinding.ivTitleBack.setOnClickListener { finish() }
        mViewBinding.ivTitleDelete.setOnClickListener {
           deleteConfirmDialog.show()
        }
        mVModel.deleteArticleResponse.observe(this){
            EventBus.getDefault().post(EventBusVo(2,"delete"))
            finish()
        }
    }
}